<?php

/*
 * Copyright (C) 2014 koodo@qq.com.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */

/**
 * 类加载器
 */
class ClassLoader {
    
    /**
     * 
     * @global type $config
     * @param type $className
     * @param type $c
     * @return boolean
     */
    public static function load($className, $c = false) {
        global $config;
        $_path = null;
        $bLoad = false;
        foreach ($config->classRoot as $_classRoot) {
            $_path = $_classRoot . $className . ".php";
            if (is_file($_path)) {
                include_once $_path;
                $c && $c->$className = new $className();
                $bLoad = true;
                break;
            }
        }
        if (!$bLoad && $config->debug) {
            die('Class file' . $_path . 'not found!<br>');
        } else {
            return true;
        }
        unset($_path);
        unset($bLoad);
    }

}
